﻿using Star.Tools.Common;
using Star.Tools.Helper;
using System.ComponentModel;

namespace Star.Tools.Files {
    /// <summary>
    /// 文件容量单位
    /// </summary>
    public enum FileSizeUnit {
        /// <summary>
        /// 字节
        /// </summary>
        [Description( "B" )]
        Byte = 1,
        /// <summary>
        /// K字节
        /// </summary>
        [Description( "KB" )]
        K = 2,
        /// <summary>
        /// M字节
        /// </summary>
        [Description( "MB" )]
        M = 3,
        /// <summary>
        /// G字节
        /// </summary>
        [Description( "GB" )]
        G = 4
    }

    /// <summary>
    /// 文件容量单位枚举扩展
    /// </summary>
    public static class FileSizeUnitExtensions
    {
        /// <summary>
        /// 获取描述
        /// </summary>
        public static string Description( this FileSizeUnit? unit ) {
            return unit == null ? string.Empty : EnumHelper.GetDescription(unit.Value);
        }

        /// <summary>
        /// 获取值
        /// </summary>
        public static int? Value( this FileSizeUnit? unit ) {
            if ( unit == null )
                return null;
            return unit.Value().Value;
        }
    }
}
